﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using Manager.App_Code;
using Manager.ViewModels;
using Manager.Common;
using System.Linq;

namespace Manager.FormAdd_Edit
{
    public partial class frm_HieuChinhDichVu : DevExpress.XtraEditors.XtraForm
    {
        NewPearl_HotelDataContext db = new NewPearl_HotelDataContext();
        public DichVuViewModel vmDichVu = null;
        public bool isClose = false;

        public frm_HieuChinhDichVu(DichVuViewModel _vmDichVu)
        {
            InitializeComponent();
            vmDichVu = _vmDichVu;
        }

        public frm_HieuChinhDichVu()
        {
            InitializeComponent();
        }

        private void frm_HieuChinhDichVu_Load(object sender, EventArgs e)
        {
            cmbTienTe.DataSource = db.TienTes.ToList();
            cmbTienTe.DisplayMember = "TenDonVi";
            cmbTienTe.ValueMember = "MaDonVi";
            txtTenDichVu.Text = vmDichVu.TenDichVu;
            txtSoLuong.Text = vmDichVu.SoLuong.ToString();
            txtGiaTien.Text = CommonFunction.AddSeparator(vmDichVu.GiaDV.Value);
            cmbTienTe.SelectedValue = vmDichVu.DonViTienTe;
        }

        private void btnCapNhat_Click(object sender, EventArgs e)
        {
            vmDichVu.TenDichVu = txtTenDichVu.Text;
            vmDichVu.SoLuong = CommonFunction.ParseInt(txtSoLuong.Text);
            vmDichVu.GiaDV = CommonFunction.ParseDouble(txtGiaTien.Text);
            vmDichVu.ThanhTien = vmDichVu.SoLuong * vmDichVu.GiaDV;
            var tienTe = cmbTienTe.SelectedItem as TienTe;
            vmDichVu.ThanhTienVND = vmDichVu.ThanhTien.Value * tienTe.TyGiaThamKhao.Value;
            this.Close();
        }

        private void btnDong_Click(object sender, EventArgs e)
        {
            isClose = true;
            this.Close();
        }

        private void txtGiaTien_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!Char.IsNumber(e.KeyChar) && !Char.IsControl(e.KeyChar))
            {
                if (e.KeyChar != '.')
                    e.Handled = true;
            }
        }
    }
}